from google.appengine.ext import db
class ShortenUrl(db.Model):
	long_url = db.StringProperty()
	refferals = db.IntegerProperty() 
	t_created = db.DateTimeProperty(auto_now_add=True)
	
	@staticmethod
	def get_or_insert(url):
		query = db.Query(ShortenUrl)
		query.filter('long_url = ', url)
		results = query.fetch(1);
		if len(results) > 0:
			db_url = results[0]
			db_url.new = False
		else:
			db_url = ShortenUrl(long_url = url, refferals = 1)
			db_url.put()
			db_url.new = True
		return db_url

